package org.gjw.security.component;

import cn.hutool.core.bean.BeanUtil;
import org.gjw.bean.SysUser;
import org.gjw.service.SysUserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

/**
 * @author guojunwang
 * @date 2021-06-26 12:01
 */
@Component
public class AuthUserDetailsService implements UserDetailsService {

    @Autowired
    private SysUserService sysUserService;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        SysUser sysUser = sysUserService.getBaseMapper().getUserByUsername(username);
        return BeanUtil.copyProperties(sysUser,AuthUserDetails.class);
    }


}
